package cn.xhjava.crm.settings.service.impl;

import cn.xhjava.crm.commons.util.DateUtils;
import cn.xhjava.crm.settings.domain.User;
import cn.xhjava.crm.settings.mapper.UserMapper;
import cn.xhjava.crm.settings.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * Author:   XiaHu
 * Date:     2023/6/20
 * 用户服务层实现
 */
@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User queryUserByLoginActAndPwd(Map<String, Object> map) throws Exception {
        return userMapper.selectUserByLoginActAndPwd(map);
    }

    @Override
    public User queryUserByLoginAct(Map<String, Object> map) throws Exception {
        return userMapper.queryUserByLoginAct(map);
    }

    @Override
    public void add(Map<String, Object> map) throws Exception {
        User user = new User();
        user.setId(UUID.randomUUID().toString().substring(0, 31));
        user.setLoginAct(map.get("loginAct").toString());
        user.setName(map.get("username").toString());
        user.setLoginPwd(map.get("loginPwd").toString());
        user.setEmail(map.get("email").toString());
        user.setExpireTime(DateUtils.getAfterData());
        user.setLockState("1");

        userMapper.insert(user);
    }

    @Override
    public List<User> queryAllUsers() throws Exception {
        return userMapper.selectAllUsers();
    }

    @Override
    public int update(User user) throws Exception {
        return userMapper.updateByPrimaryKey(user);
    }
}
